package com.cskaoyan.service.admin;

import com.cskaoyan.bean.MarketLog;
import com.cskaoyan.bean.MarketLogExample;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketLogMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService{

    @Autowired
    MarketLogMapper marketLogMapper;

    @Override
    public CommonData getLogList(Integer page, Integer limit, String name) {
        PageHelper.startPage(page, limit);
        MarketLogExample example = new MarketLogExample();
        MarketLogExample.Criteria criteria = example.createCriteria();

        if (name != null && !"".equals(name)) {//StringUtils isEmpty
            criteria.andAdminLike("%"+name+"%");
        }
        criteria.andDeletedEqualTo(false);

        List<MarketLog> marketLogMappers = marketLogMapper.selectByExample(example);
        PageInfo pageInfo = new PageInfo(marketLogMappers);
        CommonData commonData = new CommonData();
        commonData.setLimit(limit);
        commonData.setPage(pageInfo.getPageNum());
        commonData.setTotal((int) pageInfo.getTotal());
        commonData.setPages(pageInfo.getPages());
        commonData.setList(marketLogMappers);
        return commonData;
    }
}
